package com.eedi.framework.job.controller.org;


import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.job.controller.org.vo.log.OrgJobLogPageReq;
import com.eedi.framework.job.controller.org.vo.log.OrgJobLogResp;
import com.eedi.framework.job.dal.dataobject.OrgJobLogDO;
import com.eedi.framework.job.service.OrgJobLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "经营界面 - 定时任务日志")
@RestController
@RequestMapping("/job-log")
@Validated
public class JobLogController {

    @Resource
    private OrgJobLogService orgJobLogService;

    @GetMapping("/get")
    @Operation(summary = "获得定时任务日志(org:job-log:query)")
    @Parameter(name = "orgJobLogId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@sys.hasPermission('org:job-log:query')")
    public CommonResult<OrgJobLogResp> getJobLog(@RequestParam("orgJobLogId") String orgJobLogId) {
        OrgJobLogDO jobLog = orgJobLogService.getJobLog(orgJobLogId);
        return success(BeanUtils.toBean(jobLog, OrgJobLogResp.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得定时任务日志分页(org:job-log:query)")
    @PreAuthorize("@sys.hasPermission('org:job-log:query')")
    public CommonResult<PageResult<OrgJobLogResp>> getJobLogPage(@Valid OrgJobLogPageReq pageVO) {
        PageResult<OrgJobLogDO> pageResult = orgJobLogService.getJobLogPage(pageVO);
        return success(BeanUtils.toBean(pageResult, OrgJobLogResp.class));
    }

}
